import { createElement, HTMLAttributes, type FC } from 'react';
import classNames from 'classnames';

import { feedDefaultProps } from './defaultProps';
import type { FeedOptions } from './type';
import FeedEvent from './FeedEvent';
import FeedLabel from './FeedLabel';
import FeedContent from './FeedContent';
import FeedSummary from './FeedSummary';
import FeedUser from './FeedUser';
import FeedDate from './FeedDate';
import FeedMeta from './FeedMeta';
import FeedLike from './FeedLike';
import FeedExtra from './FeedExtra';

export interface FeedProps extends FeedOptions, HTMLAttributes<HTMLDivElement> {}

interface FeedInterface extends FC<FeedProps> {
  Event: typeof FeedEvent;
  Label: typeof FeedLabel;
  Content: typeof FeedContent;
  Summary: typeof FeedSummary;
  Extra: typeof FeedExtra;
  User: typeof FeedUser;
  Date: typeof FeedDate;
  Meta: typeof FeedMeta;
  Like: typeof FeedLike;
}

const Feed: FeedInterface = (props) => {
  const { className, size, inverted, children, forwardedRef, ...feedProps } = props;

  return createElement(
    'div',
    { ref: forwardedRef, className: classNames('ui', { size, inverted }, 'feed', className), ...feedProps },
    children,
  );
};

Feed.displayName = 'Feed';
Feed.defaultProps = feedDefaultProps;

Feed.Event = FeedEvent;
Feed.Label = FeedLabel;
Feed.Content = FeedContent;
Feed.Summary = FeedSummary;
Feed.Extra = FeedExtra;
Feed.User = FeedUser;
Feed.Date = FeedDate;
Feed.Meta = FeedMeta;
Feed.Like = FeedLike;

export default Feed;
